#adapted from http://www.boddie.org.uk/python/XML_intro.html
import xml.dom.minidom
#dir(xml.dom.minidom) list contents of module

#create a new xml doc
def get_a_document():
    doc = xml.dom.minidom.Document()
    markers_element = doc.createElementNS("motologger","markers")#add markers as root element with namespace motologger
    doc.appendChild(markers_element) #adds to markers_element to document
    return doc, markers_element

doc,markers_element = get_a_document()

def add_a_line(doc, markers_element):
    line_element = doc.createElementNS("motologger","line")
    markers_element.appendChild(line_element)
    return line_element

line_element = []
line_element.append([])
line_element[0] = add_a_line(doc, markers_element)

line_element[0].setAttribute("colour","#0000FF")
line_element[0].setAttribute("width","4")
line_element[0].setAttribute("html","123")
#line_element = add_a_line(doc,markers_element)

def add_a_point(doc, line_element):
    point_element = doc.createElementNS("motologger","point")
    line_element.appendChild(point_element)
    return point_element

point_element = []
point_element.append([])
point_element[0] = add_a_point(doc, line_element[0])

point_element[0].setAttribute("lat","43.8")
point_element[0].setAttribute("lng","-79.0")

point_element.append([])
point_element[1] = add_a_point(doc, line_element[0])

point_element[1].setAttribute("lat","45.8")
point_element[1].setAttribute("lng","-79.0")

xml_file = open('new.xml','w')

doc.writexml(xml_file, "", "    ", "\n", "UTF-8")

xml_file.close()


